﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XSTDZ.ERP.Core.Generator;
using XSTDZ.ERP.Core.Extentions;


namespace XSTDZ.ERP.Domain.Models
{
    /// <summary>
    /// 调拔
    /// </summary>
    public partial class ProductAllot
    {
        public ProductAllot()
        {
            this.ProductAllotDetail = new HashSet<ProductAllotDetail>();
        }

        public ProductAllot Init()
        {
            if (this.Id.Equals(Guid.Empty))
            {
                this.Id = (Guid)new SequentialIdentityGenerator().Next;
            }
            this.CreateTime = DateTime.Now;
            this.Deleted = 0;
           
            return this;
        }

        public ProductAllot AddDetail(ProductAllotDetail detail)
        {
            if (!this.ProductAllotDetail.Contains(detail))
            {
                if (detail.ProductAllotID == null || detail.ProductAllotID.Equals(Guid.Empty))
                {
                    detail.ProductAllotID = this.Id;
                }
                this.ProductAllotDetail.Add(detail.Init());
            }
            return this;
        }

        public ProductAllot AddDetails(IEnumerable<ProductAllotDetail> details)
        {
            details.Each(d => AddDetail(d));
            return this;
        }

        public ProductAllot ClearAllChildren()
        {
            this.ProductAllotDetail.Clear();
            return this;
        }
    }
}
